﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLToolkit.Data;

namespace MvcVietAir.Models
{
    public class RepositoryFlights
    {
        private DbManager db = new DbManager("MvcVietAirConnectionString");
        
        public List<Flight> GetAll()
        {
            using (db)
            {
                return db.SetSpCommand("Flight_All").ExecuteList<Flight>();
            }
        }

        public List<Flight> FindByAirline(string name)
        {
            using (db)
            {
                return db.SetSpCommand("Flight_FindByAirline",db.Parameter("@Name",name)).ExecuteList<Flight>();
            }
        }
        public List<Flight> FindFlights(string airline, DateTime dateflight, string from, string to)
        {
            using (db)
            {
                return db.SetSpCommand("Flight_FindFlights", db.Parameter("@Airline", airline), db.Parameter("@DateFlight", dateflight), db.Parameter("@PositionFrom", from), db.Parameter("@PositionCome", to)).ExecuteList<Flight>();
            }
        }
        public List<Flight> FindFlights(string airline, DateTime dateflight, string from, string to, string type)
        {
            using (db)
            {
                return db.SetSpCommand("Flight_FindFlightsType", db.Parameter("@Airline", airline), db.Parameter("@DateFlight", dateflight), db.Parameter("@PositionFrom", from), db.Parameter("@PositionCome", to), db.Parameter("")).ExecuteList<Flight>();
            }
        }
        public List<Flight> FindByDateFlight(DateTime DateFlight)
        {
            using (db)
            {
                return db.SetSpCommand("Flight_FindByDateFlight", db.Parameter("@DateFlight", DateFlight)).ExecuteList<Flight>();
            }
        }
        public Flight Single(string Id)
        {
            using (db)
            {
                return db.SetSpCommand("Flight_Single", db.Parameter("@Id", Id)).ExecuteObject<Flight>();
            }
        }
        public int Create(Flight flight)
        {
            using (db)
            {
                return db.SetSpCommand("Flight_Create", db.CreateParameters(flight)).ExecuteNonQuery();
            }
        }
        public int Edit(Flight flight)
        {
            using (db)
            {
                return db.SetSpCommand("Flight_Edit", db.CreateParameters(flight)).ExecuteNonQuery();
            }
        }
        public int Delete(string Id)
        {
            using (db)
            {
                return db.SetSpCommand("Flight_Delete", db.Parameter("@Id", Id)).ExecuteNonQuery();
            }
        }
    }
}